<!-- 详情页 头部 -->
<template>
    <div>
        <router-link tag="div" to="/" class="header-abs" v-show="showAbs">
            <i class="iconfont back-icon">&#xe624;</i>
        </router-link>
        <div class="header-fixed"  v-show="!showAbs" :style="opactiyStyle">
            <router-link to="/">
                <i class="iconfont back-icon">&#xe624;</i>
            </router-link>
            景点详情
        </div>
    </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data() {
    return {
      showAbs: true,
      opactiyStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll() {
      const scroll_top = document.documentElement.scrollTop
      console.log(scroll_top)
      if (scroll_top > 60) {
        let opacity = scroll_top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opactiyStyle = {
          opacity: opacity
        }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  // keepalive下的生命周期函数
  // 在每次页面展示时会执行
  activated() {
    // 全局事件,能影响其他组件，要解绑
    window.addEventListener('scroll', this.handleScroll)
  },
  // 在页面即将被替换时会执行
  deactivated() {
    // 对全局事件解绑
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl'
@import '~styles/mixins.styl'
.header-abs
  position absolute
  left 0.2rem
  top 0.2rem
  width 0.7rem
  height 0.7rem
  line-height 0.7rem
  border-radius 50%
  text-align center
  background rgba(0, 0, 0, 0.8)
  .back-icon
    color #fff
    font-size 0.3rem;
    margin-right: .06rem;
.header-fixed
  z-index 2
  position fixed
  top 0
  left 0
  width 100%
  height 0.86rem
  line-height 0.86rem
  text-align center
  color #fff
  background $bgColor
  font-size 0.32rem
  .back-icon
    position absolute
    left 0
    top 0
    width 0.64rem
    text-align center
    font-size 0.32rem
    color #fff
</style>

